#include<bits/stdc++.h>
using namespace std;
const int MAXN = 101;
const int INF = 1e9;

int n, m, s;
int e[MAXN][MAXN];
int main() {
    //freopen("A.in", "r", stdin);
    cin >> n;
    s++;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            int t;
            cin >> t;
            if (i == j) t = 0;
            else if (t == 0)t = INF;
            e[i][j] = t;
        }
    }

    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (e[i][k] + e[k][j] < e[i][j]) {
                    e[i][j] = e[i][k] + e[k][j];
                }
            }
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cout<<e[i][j]<<" ";
        }
        cout<<endl;
    }

}